|
CruiseControl.NET : Using CruiseControl.NET with NUnit
This page last changed on Sep 15, 2005 by richardjfoster.
Integrating NUnit into your build in the CruiseControl.NET ServerThe typical way to integrate the CruiseControl.NET Server with NUnit is to run NUnit as part of your Build Process. This is the recommended mechanism since it means developers are using a build process closer to the integration process. If you're using NAnt, you'll either be using an <exec> task or <nunit> task to do this (we recommend using <exec> - its more stable across changing versions of NUnit.) Make sure to use xml output. A line out of CruiseControl.NET's own build file is below, as an example: <exec program="${nunit-console.exe}" workingdir="${build.dir}\core" commandline="${core.dll} /xml:../${core.dll}-results.xml /nologo"/>
If you are not using a scripted build, you can also use the NUnit Task. We don't recommend this, but its up to you. Once you've got NUnit running, use a File Merge Task to include the NUnit results into your build results file - you'll need to make sure you're including all the NUnit xml files. Finally, make sure you're using an Xml Log Publisher. Integrating NUnit results into the Build ReportCruiseControl.NET, by default, attempts to style the NUnit output into useful results in the reporting applications. If the results aren't showing up look at the help on the File Merge Task page. Allowing multiple NUnit test assemblies to run, even if there are some test failures.The typical operation of CruiseControl, NAnt (or MSBuild) and NUnit means that if there is a failure in the tests performed by the first assembly, the build process will terminate. This operation is by design. One of the principles of Continuous Integration is that build failures are reported as quickly as possible. Since CruiseControl already knows that the build has failed, there is no point running the other tests! If you are using a build tool like NAnt, you can change this operation by modifying the build script so you control when the failure is reported. The example below describes how to create a NAnt target which will run both sets of tests, even if the first one fails. Assume you have two NUnit test assemblies, let' s call them UnitTestAssembly.dll and AcceptanceTestAssembly.dll. Your initial NAnt script would probably contain something like this: <target name="test" description="runs the unit and acceptance tests"> <!-- Unit Test Assembly --> <exec program="${nunit-console.exe}"> <arg value="UnitTestAssembly.dll" /> <arg value="/xml=UnitTestAssembly-Results.xml" /> </exec> <!-- Acceptance Test Assembly --> <exec program="${nunit-console.exe}"> <arg value="AcceptanceTestAssembly.dll" /> <arg value="/xml=AcceptanceTestAssembly-Results.xml" /> </exec> </target> The first thing you might be tempted to try is to add the failonerror attribute to the <exec> task, however while this allows both sets of tests to run, it also means that NAnt no longer reports the failure back to CruiseControl (although the failure does still appear in the build log). To solve this problem, modify the NAnt script as shown below: <target name="test" description="runs the unit tests"> <!-- Unit Test Assembly --> <exec program="nunit-console.exe" failonerror="false" resultproperty="testresult.unittestassembly"> <arg value="UnitTestAssembly.dll" /> <arg value="/xml=UnitTestAssembly-Results.xml" /> </exec> <!-- Acceptance Test Assembly --> <exec program="nunit-console.exe" failonerror="false" resultproperty="testresult.acceptancetestassembly"> <arg value="AcceptanceTestAssembly.dll" /> <arg value="/xml=AcceptanceTestAssembly-Results.xml" /> </exec> <!-- Check the results and fail if necessary --> <fail message="Failures reported in unit tests." unless="${int::parse(testresult.unittestassembly)==0}" /> <fail message="Failures reported in acceptance tests." unless="${int::parse(testresult.acceptancetestassembly)==0}" /> </target> |
| Document generated by Confluence on Mar 14, 2009 02:55 |